package com.jlkf.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jlkf.dao.OrderItemsMapper;
import com.jlkf.dao.SugFeedbackMapper;
import com.jlkf.dao.UserMapper;
import com.jlkf.pojo.OrderItems;
import com.jlkf.pojo.SugFeedback;
import com.jlkf.pojo.User;
import com.jlkf.service.SugFeedbackService;
import com.jlkf.service.util.StringTools;
import com.platform.server.response.pojo.ReturnData;
@Service
public class SugFeedbackServiceImpl implements SugFeedbackService{

	@Autowired
	private SugFeedbackMapper sugFeedbackMapper;
	@Autowired
	private OrderItemsMapper orderItemsMapper;
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public ReturnData addSugFeedback(String json) {
		SugFeedback sf=StringTools.json2Obj(json, SugFeedback.class);
		if(sf==null){
			return new ReturnData(201,"The parameter list cannot be empty！");
		}
		sf.setMsgdate(new Date());
		try {
			OrderItems oi=orderItemsMapper.selectByPrimaryKey(sf.getOrderId());
			if(oi!=null){
				sf.setDriverId(oi.getDirberId());
				User u=userMapper.selectByPrimaryKey(oi.getDirberId());
				sf.setAccount(u.getTelephone());
				sf.setOrderNo(oi.getOrderNo());
			}
			int num=sugFeedbackMapper.insertSelective(sf);
			if(num==0){
				return new ReturnData(202,"Submit fail");
			}
			return new ReturnData(200,"Submit success");
		} catch (Exception e) {
			e.printStackTrace();
			return new ReturnData(500,"Wow, that's wrong");
		}
	}

	
}
